package com.bing.habit.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * @author: xujiabing
 * @date: 2024-09-30 11:07
 * @description 用于项目启动时打印配置
 */
@Component
@Slf4j
public class ConfigPrinter implements CommandLineRunner {
    @Value("${image.save.uploadSwitch}")
    private boolean isNotOss;
    @Value("${image.save.path}")
    private String path;
    @Value("${server.port}")
    private String port;
    @Value("${server.servlet.context-path}")
    private String contextPath;
    @Value("${spring.cloud.alicloud.oss.bucket}")
    private String bucketName;

    @Override
    public void run(String... args) throws Exception {
        //打印是否启用oss
        if (!isNotOss) {
            log.info("启用阿里云oss,进行图片存储,桶名 = {}",bucketName);
            //System.out.println("启用oss对象存储进行图片上传");
        } else {
            log.info("使用本地路径进行图片上传 = {}", path);
            //System.out.println("使用本地路径进行图片上传:  " + path);
        }
        //项目端口，以及上下文路径
        InetAddress inetAddress = InetAddress.getLocalHost();
        String ipAddress = inetAddress.getHostAddress();
        log.info("启动地址 = {}",ipAddress + ":" + port + contextPath);
    }
}
